/**
 * 互动界面
 */
class interactionSub extends eui.Component{
    private return:eui.Button;
    private list:eui.List;
    private _arrayCollection:eui.ArrayCollection;
    private _arrayData:Array<any>;
    public constructor(){
        super();
       // this.cacheAsBitmap =true;
        this.addEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent,this);
        this.skinName = "interactionSkin"; 
    }

    private createCompleteEvent():void{
        this.removeEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent, this);
        this.inIt();
    }

    private inIt(){
        this.return.addEventListener(egret.TouchEvent.TOUCH_TAP,()=>{
            this.dispatchEventWith("return");
        },this);

        Dispatcher.ins.addEventListener("interactList",this.reset,this);

        socket.request("interactList");
        this._arrayCollection = new eui.ArrayCollection(this._arrayData);
        this.list.itemRenderer = interactionIR;
        this.list.dataProvider = this._arrayCollection;
    }

    public reset(evt:GameEvent){
        let obj = evt.data;
        let list = obj.list;
        let time = "";
        this._arrayData = [];
        for(let i = 0,lg = list.length;i < lg;i ++){
            let str = list[i];
            let nowtime = str.LogTime.substr(0,10);
            str.date = nowtime;
            str.time = str.LogTime.substr(11,5);
            str.text = str.Msg + str.WaterCount + "次";
            if(nowtime !== time){
                str.node = 0;
                time = nowtime;
            }else{
                str.node = 1;
            }
            this._arrayData.push(str);
        }
        this._arrayCollection = new eui.ArrayCollection(this._arrayData);
        this.list.dataProvider = this._arrayCollection;
        this._arrayCollection.refresh();
    }
}
class interactionIR extends eui.ItemRenderer{
    private maskBg:eui.Rect;
    private head:eui.Image;
    private topGroup:eui.Group;
    public constructor(){
        super();
        this.addEventListener(eui.UIEvent.COMPLETE , this.createCompleteEvent,this);
        this.skinName = "interactionIRSkin";
    }
    private createCompleteEvent():void{
        super.createChildren();
        this.head.mask = this.maskBg;
    }
    protected dataChanged():void{
        if(this.data.node == 0){
            this.topGroup.visible = true;
            this.topGroup.height = 90;
        }else{
            this.topGroup.visible = false;
            this.topGroup.height = 0;
        }
    }
}